package com.anjiplus.template.gaea.business.GeneralToolService.impl;

import com.anjiplus.template.gaea.business.GeneralToolService.GsOrgService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class GsOrgServiceImpl implements GsOrgService {
    @Value("${spring.datasource.GSYY}")
    private String GSYY;

    @Override
    public List<Map<String, Object>> selectAllGsCode(JdbcTemplate jdbcTemplate) {
        //判断中间库是否已经存在，如已存在，不同步
        String selectSQL = "SELECT NAME,YYCODE,YYZTCODE,GSCODE,GSZTCODE,KMTX,YYORGPK,YYZTNAME,ISJT,YYKMTX FROM " + GSYY + ".YY_ORG_ORGS WHERE GSCODE IS NOT NULL";
        return jdbcTemplate.queryForList(selectSQL);
    }

    @Override
    public  List<Map<String, Object>>  selectCusZtCode(JdbcTemplate jdbcTemplate) {
        String yyztCode = "";
        //判断中间库是否已经存在，如已存在，不同步
        String selectSQL = "select DISTINCT (CASE WHEN ISJT = 'Y' THEN GSCODE ELSE GSZTCODE END ) AS yyztCode, gsCode from "+GSYY+".yy_org_orgs where gsCode is not null";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(selectSQL);
        return maps;
    }

    @Override
    public  List<Map<String, Object>>  selectJTZtCode(JdbcTemplate jdbcTemplate) {
        String yyztCode = "";
        //判断中间库是否已经存在，如已存在，不同步
        String selectSQL = "SELECT DISTINCT gsCode from "+GSYY+".YY_ORG_ORGS WHERE GSCODE IS NOT NULL";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(selectSQL);
        return maps;
    }
}
